home *** CD-ROM | disk | FTP | other *** search
- /* vscanf.c --- p 481 */
- #include <stdio.h>
- #include <stdarg.h>
- void getinput(char *,...);
- main()
- {
- int accno;
- double price, discount;
- /* call the input routine to read values of variables.
- * First just a single number. Then more than one value. */
- printf("Enter acount number:");
- getinput(" %d", &accno);
- printf("\nEnter price and discount (\%) separated by a space:");
- getinput(" %lf %fl", &price, &discount);
- printf("$%.2f @%.2f%% discount = $%.2f\n", price,
- discount, price*(1.0-discount/100.));
- }
- /*---------------------------------*/
- /* getinput: accepts variable number of arguments
- * and reads formatted values */
- void getinput(char *my_format,...)
- {
- va_list arg_pointer;
- /* Use va_start macro to get to the start of the
- * variable number of arguments. This will alter the
- * pointer arg_pointer to point to the list of
- * variables to be read. */
- va_start(arg_pointer, my_format);
- vscanf(my_format, arg_pointer);
- /* Use the va_end macro to reset the arg_pointer */
- va_end(arg_pointer);
- }